//
//  WBBasicController.m
//  sinaWeibo
//
//  Created by 李江波 on 2016/11/14.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WBBasicController.h"
#import "WBNavController.h"

#import "WBOAuthController.h"
#import "WBOAuthViewModel.h"

#import <YYModel.h>

@interface WBBasicController ()

@property(nonatomic ,assign) BOOL isLogin;



@end

@implementation WBBasicController

//懒加载
-(UINavigationBar *)navBar{

    if (nil == _navBar) {
        _navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
    }
    return _navBar;
}

-(UINavigationItem *)navItem{

    if (nil == _navItem) {
        
        _navItem = [[UINavigationItem alloc]init];
    }
    return _navItem;
}

-(void)loadView{
    
    _isLogin = [WBOAuthViewModel shared].isLogin;

    if (_isLogin) {
        
        [super loadView];
        
        [self setupUI];
    }else{
    
        _visitorV = [[WBVisitorView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        
        self.view = _visitorV;
        
        [self setupNav];
    }
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    _visitorV.registerBlock = ^{
    
        NSLog(@"注册被点了");
    };
    
    __weak typeof(self) weakSelf = self;
    _visitorV.loginBlock = ^{
    
        NSLog(@"登录被点了");
        WBOAuthController *vc = [[WBOAuthController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        
        [weakSelf presentViewController:nav animated:YES completion:nil];
    };
    
}


/**
 新建tableview
 */
-(void)setupUI{

    UITableView *tableV = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    tableV.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
    
    tableV.delegate = self;
    tableV.dataSource = self;
    
    _tableV = tableV;
    
    [self.view addSubview:tableV];
    
    [self setupNav];
}


/**
 重写导航栏
 */
-(void) setupNav{
    
    self.navigationController.navigationBar.hidden = true;
    
    self.navBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_navBar];
    
    _navBar.items = @[self.navItem];
    
}

-(void)setTitle:(NSString *)title{

    self.navItem.title = title;
    self.tabBarItem.title = title;
}

#pragma mark - Table view data source

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc]init];
    cell.textLabel.text = @"哈哈";
    
    return cell;
}




@end
